package org.puresilk.android.util;

import android.content.Context;
/**
 * Bag of goodies that seem to be needed
 * for lots of reasons...
 * 
 * @author david
 *
 */
public class Util {
	/**
	 * Utility missing from Java!!!
	 * 
	 * @param cols
	 * @param delimiter
	 * @return
	 */
	public static String join(String [] cols, String delimiter) {
        StringBuilder buffer = new StringBuilder();
        
        for(int i=0; i < cols.length; i++){
        	if (buffer.length() > 0)
        		buffer.append(delimiter);
        	buffer.append(cols[i]);
        }
        return buffer.toString();
    }

	/**
	 * find resource by context and name.
	 * @param ctx
	 * @param entity
	 * @return
	 */
	public static int getResourceId(Context ctx,String entity,String type){
		String rsrcStr = String.format("%3$s:%2$s/%1$s",entity, type,ctx.getPackageName());
		return ctx.getResources().getIdentifier(rsrcStr,null,null);
	}
}
